package com.infore.exchange.main.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.infore.common.model.entity.exchange.TJobInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 作业信息表 Mapper 接口
 * </p>
 *
 * @author lijh
 * @since 2023-02-13
 */
@Mapper
@Component
public interface TJobInfoMapper extends BaseMapper<TJobInfo> {


    @Update(" update t_ex_job_info set job_state = #{status} where job_id=#{jobId}")
    int updateJobStateById(@Param("jobId")  String jobId,@Param("status")  Integer status);

    @Update(" update t_ex_job_info set prev_exec_time = #{preTime},next_exec_time=#{nextTime} where job_id=#{jobId}")
    int updateExecTime(@Param("jobId") String jobId, @Param("preTime") Date preTime, @Param("nextTime") Date nextTime);


    @Select("<script>" +
            "select * from t_ex_job_info where job_id in (select distinct job_id from t_ex_job_task_info) " +
            " <if test='jobId != null and jobId != \"\"'> " +
            "  and job_id=#{jobId} " +
            " </if> " +
            " <if test='jobState != null'> " +
            "  and job_state=#{jobState} " +
            " </if> " +
            "</script>")
    List<TJobInfo> queryHaveTaskJobInfo(@Param("jobId") String jobId, @Param("jobState") Integer jobState);


}
